package org.point.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.impl.CreditsTypeDaoImpl;
import org.point.domain.CreditsType;
import org.point.service.CreditsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: CreditsTypeServiceImpl  
 * @Description: TODO(积分类型业务实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01  
 *
 */
@Service("creditsTypeService")
public class CreditsTypeServiceImpl extends BaseServiceImpl<CreditsType, Serializable> implements CreditsTypeService {
	
	@Autowired
	private CreditsTypeDaoImpl dao;

	public List<CreditsType> searchCT(DoPage<CreditsType> page) {
		List<CreditsType> record = dao.findCTForMem(page);
		return record;
	}
	
	public DoPage<CreditsType> searchCRForPage(DoPage<CreditsType> page) {
		List<CreditsType> records = dao.findCTForMem(page);
		Integer totalRecords = dao.countCTForMem(page);
		page.setList(records);
		page.setTotalRecords(totalRecords);
		return page;
	}

	public Integer countCT(DoPage<CreditsType> page) {
		Integer count = dao.countCTForMem(page);
		return count;
	}
	
	public Integer insertCT(CreditsType record,String ctCode) {
		Integer result = 0;
		if(record.getId()!=null){
			Integer isdel = dao.delCTbyId(record.getId().toString());
			Integer newResult = dao.insertCT(record);
			if(isdel+newResult>0){
				result = 1;
			}
		}else{
			record.setCreditsTypeId(ctCode);
		    result = dao.insertCT(record);
		}
		return result;
	}

	public Integer editCreditsType(CreditsType record) {
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("delFlag", 0);
		map.put("creditsTypeId", record.getCreditsTypeId());
		// 修改积分规则分类删除状态
		Integer delRsult = dao.updDelflag(map);
		// 修改积分规则分类删除状态成功，则新增积分规则分类
		if(delRsult == 1){
			result = dao.insert(record);
		}
		return result;
	}
	
	public Integer editCtStatus(Map<String, Object> map) {
		Integer result = dao.updStatus(map);
		return result;
	}

	public CreditsType getCTByCTID(Map<String, Object> map) {
		CreditsType record = dao.searchForCT(map);
		return record;
	}

	public Integer deleteCTs(Map<String, Object> map) {
		Integer result = dao.deleteCTs(map);
		return result;
	}
	

}
